package com.ufo.store.management.ui.activity;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.Window;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ufo.store.management.BarApplication;
import com.ufo.store.management.R;
import com.ufo.store.management.adapter.Isszmbalv3CalenderViewPagerAdapter;
import com.ufo.store.management.calendar.LunarCalendar;
import com.ufo.store.management.database.DatabaseManager;
import com.ufo.store.management.entity.Isszmbalv3BranchInfo;
import com.ufo.store.management.entity.Isszmbalv3PayFlow;
import com.ufo.store.management.entity.Isszmbalv3PayFlowGroup;
import com.ufo.store.management.entity.SerializableList;
import com.ufo.store.management.ui.fragment.Isszmbalv3CalenderFragment;
import com.ufo.store.management.utils.DialogUtil;
import com.ufo.store.management.utils.ScreenUtil;
import com.ufo.store.management.utils.StatusBarUtil;
import com.ufo.store.management.utils.Utils;
import com.ufo.store.management.widget.dialog.BranchDialog;
import com.ufo.store.management.widget.view.ArcProgress;
import com.ufo.store.management.widget.dialog.CalendarDialog;

import java.sql.Date;
import java.sql.Time;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  作者：taoli on 2017/2/13 0013 13:58
 *  
 */
public class Isszmbalv3PayMasterActivity extends BaseActivity{
    public static final String TAG = Isszmbalv3PayMasterActivity.class.getSimpleName();
    public static final int CALENDER_DAY_COUNT = 365;

    private AppBarLayout appBarLayout;
    private Toolbar toolBar;
    private CollapsingToolbarLayout coordinatorLayout;

    private ViewPager mCalenderViewPager = null;
    private Isszmbalv3CalenderViewPagerAdapter mCalenderAdapter = null;

    private TextView paymaster_tips_tv = null;
    private TextView mPayMasterDateTv = null;
    private TextView paymaster_datetime_tv = null;
    private TextView mPayMasterBlotoutTv = null;
    private TextView mPayMasterTotalTv = null;
    private TextView paymaster_vip_tv = null;
    private TextView paymaster_novip_tv = null;
    private LinearLayout paymaster_total_ll = null;
    private LinearLayout paymaster_blotout_ll = null;
    private LinearLayout paymaster_wx_payment_ll = null;
    private LinearLayout paymaster_zfb_payment_ll = null;
    private ArcProgress mArcProgress = null;

    private int mReadIndex = 0;
    private Object mLock = new Object();
    private int mPosition = CALENDER_DAY_COUNT-1;
    private String mSearchDate = null;
    private String mSearchDateZh = null;
    private String mSearchBranchNo = "";

    private List<Isszmbalv3BranchInfo> mIsszmbalv3BranchInfoList = null;
    private List<Isszmbalv3PayFlow> mIsszmbalv3PayFlowInfoList = null;
    private List<Isszmbalv3PayFlowGroup> mIsszmbalv3PayFlowGroupInfoList = new ArrayList<Isszmbalv3PayFlowGroup>();

    private BranchDialog mBranchDialog;
    private LunarCalendar mLunarCalendar = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
        initView();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.paymaster_menu, menu);
        return true;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            finishAfterTransition();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    private Toolbar.OnMenuItemClickListener onMenuItemClickListener=new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            switch (menuItem.getItemId()){
                case R.id.action_branch:
                    showBranch();
                    break;
                case R.id.action_calendar:
                    showCalendar();
//                    getIsszmbalv3PayMasterInfoList(true);
//                    mCalenderAdapter.setRefresh();
                    break;
                case R.id.action_search:

                    break;
                case R.id.action_delete:
                    showDeleteItemDialog();
                    break;
            }
            return true;
        }
    };

    private void initData() {
        mLunarCalendar = new LunarCalendar();
        Intent intent = getIntent();
        if (intent != null) {
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                SerializableList p = (SerializableList) bundle.getSerializable("Isszmbalv3BranchInfoList");
                mIsszmbalv3BranchInfoList = p.getIsszmbalv3BranchInfoList();
            }
        }
    }

    private void initView() {
        setContentView(R.layout.activity_isszmbalv3_paymaster);
        StatusBarUtil.setStatusBarColor(this,R.color.transparent,true);
        toolBar= (Toolbar) findViewById(R.id.tool_bar);
        //这个属性必须在setSupportActionBar(toolbar)之前调用  .
        toolBar.setTitle("");
        setSupportActionBar(toolBar);
        //设置导航Icon，必须在setSupportActionBar(toolbar)之后设置  
        toolBar.setOnMenuItemClickListener(onMenuItemClickListener);
        toolBar.setNavigationIcon(R.drawable.ic_back_light_selector);
        toolBar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finishAfterTransition();
            }
        });

        coordinatorLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
        coordinatorLayout.setCollapsedTitleTextColor(Color.parseColor("#3c3c3c"));
        coordinatorLayout.setExpandedTitleColor(Color.parseColor("#5c5c5c"));
        appBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout);
        appBarLayout.addOnOffsetChangedListener(onOffsetChangedListener);

        mArcProgress = (ArcProgress) findViewById(R.id.ap);
        paymaster_tips_tv = ((TextView) findViewById(R.id.paymaster_tips_tv));
        mPayMasterDateTv = ((TextView) findViewById(R.id.paymaster_date_tv));
        paymaster_datetime_tv = ((TextView) findViewById(R.id.paymaster_datetime_tv));
        mPayMasterTotalTv = ((TextView) findViewById(R.id.paymaster_total_tv));
        mPayMasterBlotoutTv = (TextView) findViewById(R.id.paymaster_blotout_tv) ;

        paymaster_vip_tv = (TextView)findViewById(R.id.paymaster_vip_tv);
        paymaster_novip_tv = (TextView)findViewById(R.id.paymaster_novip_tv);
        paymaster_total_ll = (LinearLayout) findViewById(R.id.paymaster_total_ll) ;
        paymaster_blotout_ll = (LinearLayout) findViewById(R.id.paymaster_blotout_ll) ;
        paymaster_wx_payment_ll = (LinearLayout) findViewById(R.id.paymaster_wx_payment_ll) ;
        paymaster_zfb_payment_ll = (LinearLayout) findViewById(R.id.paymaster_zfb_payment_ll) ;

        mCalenderViewPager = ((ViewPager) findViewById(R.id.viewpager));
        mCalenderViewPager.setOnPageChangeListener(new CalenderPageChangeListener());
        mCalenderAdapter = new Isszmbalv3CalenderViewPagerAdapter(getSupportFragmentManager());
        mCalenderAdapter.setBranchNo(mSearchBranchNo);
        mCalenderViewPager.setAdapter(mCalenderAdapter);
        mCalenderViewPager.setCurrentItem(CALENDER_DAY_COUNT - 1);
        mCalenderViewPager.setOffscreenPageLimit(0);
        mCalenderAdapter.setCalenderClickListener(new Isszmbalv3CalenderFragment.CalenderClickListener() {
            @Override
            public void onAccountsNumberClick() {
                showPayListActivity();
            }
        });

        getIsszmbalv3PayMasterInfoList(true);

        Transition transition = TransitionInflater.from(this).inflateTransition(R.transition.changebounds_with_arcmotion);
        transition.addListener(new Transition.TransitionListener() {
            @Override
            public void onTransitionEnd(Transition transition) {
                animateRevealShow(appBarLayout);
            }

            @Override
            public void onTransitionStart(Transition var1){

            }

            @Override
            public void onTransitionCancel(Transition var1){

            }

            @Override
            public void onTransitionPause(Transition var1){

            }

            @Override
            public void onTransitionResume(Transition var1){

            }
        });
        getWindow().setSharedElementEnterTransition(transition);

        Transition transition1= TransitionInflater.from(this).inflateTransition(R.transition.window_enter_transition);
        transition1.addListener(new Transition.TransitionListener() {
            @Override
            public void onTransitionStart(Transition transition) {

            }

            @Override
            public void onTransitionEnd(Transition transition) {
                transition.removeListener(this);
            }

            @Override
            public void onTransitionCancel(Transition transition) {

            }

            @Override
            public void onTransitionPause(Transition transition) {

            }

            @Override
            public void onTransitionResume(Transition transition) {

            }
        });
        getWindow().setEnterTransition(transition1);
    }

    private void animateRevealShow(View viewRoot) {
        int cx = (viewRoot.getLeft() + viewRoot.getRight()) / 2;
        int cy = (viewRoot.getTop() + viewRoot.getBottom()) / 2;
        int finalRadius = Math.max(viewRoot.getWidth(), viewRoot.getHeight());
        Animator anim = ViewAnimationUtils.createCircularReveal(viewRoot, cx, cy, 0, finalRadius);
        viewRoot.setVisibility(View.VISIBLE);
        anim.setDuration(500);
        anim.setInterpolator(new AccelerateInterpolator());
        anim.start();
    }

    public void showDeleteItemDialog( ) {
        DialogUtil.showDeleteItemDialog(this, mSearchDate + "的营业记录吗", new Runnable() {
            @Override
            public void run() {
            }
        }, new Runnable() {
            @Override
            public void run() {
                new DeleteIsszmbalv3PayMasterInfoTask().execute();
            }
        });
    }

    private void showBranch(){
        if (mBranchDialog == null) {
            mBranchDialog = new BranchDialog(getActivity());
            Window window = mBranchDialog.getWindow(); //得到对话框
            window.setWindowAnimations(R.style.dialog_anim_center_style); //设置窗口弹出动画
        }
        mBranchDialog.setTips("门店选择");
        mBranchDialog.setBranchInfoList(mIsszmbalv3BranchInfoList, mSearchBranchNo);
        mBranchDialog.setItemClickListener(new BranchDialog.OnItemClick() {
            @Override
            public void onItemClick(int index, String no, String name) {
                mSearchBranchNo = no;
                mCalenderAdapter.setBranchNo(mSearchBranchNo);
                mCalenderAdapter.setRefresh();
                getIsszmbalv3PayMasterInfoList(true);
            }
        });
        mBranchDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
            }
        });
        mBranchDialog.show();
    }

    private void showCalendar(){
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, mPosition - (CALENDER_DAY_COUNT - 1));
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH);
        int day = cal.get(Calendar.DAY_OF_MONTH);
        new CalendarDialog(Isszmbalv3PayMasterActivity.this, year, month, day).setItemClickListener(new CalendarDialog.OnItemClick() {
            @Override
            public void onPositiveButtonClick(int dayOfMonth, int month, int year) {
                refreshViewPager(dayOfMonth - 1, month, year);
            }

            @Override
            public void onNegativeButtonClick() {

            }
        });
    }

    private void showPayListActivity(){
        if (mIsszmbalv3PayFlowInfoList != null) {
            Intent toIntent = new Intent(Isszmbalv3PayMasterActivity.this, Isszmbalv3PayListActivity.class);
            Bundle bundle = new Bundle();
            SerializableList p = new SerializableList();
            p.setmIsszmbalv3PayFlowGroupInfoList(mIsszmbalv3PayFlowGroupInfoList);
            bundle.putSerializable("Isszmbalv3PayFlowGroup", p);
            bundle.putString("Date", mSearchDate);
            toIntent.putExtras(bundle);
            startActivity(toIntent);
        }
    }

    private final class CalenderPageChangeListener implements ViewPager.OnPageChangeListener {
        @Override
        public void onPageScrollStateChanged(int arg0) {
            switch (arg0) {
                case 0:
                    getIsszmbalv3PayMasterInfoList(true);
                    break;
                case 1:
                    break;
                case 2:
                    break;
                default:
                    break;
            }
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageSelected(int arg0) {
            mPosition = arg0;
        }

    }

    private void refreshViewPager(int dayIndex, int monthIndex , int yearIndex) {
        calcDateIndex(dayIndex, monthIndex, yearIndex);
    }

    private void calcDateIndex(int daySelect, int monthSelect, int yearSelect){
        //当前年月日
        Calendar cal1 = Calendar.getInstance();
        String date1 = cal1.get(Calendar.YEAR) + "-" + String.valueOf(cal1.get(Calendar.MONTH) + 1) + "-" + String.valueOf(cal1.get(Calendar.DAY_OF_MONTH)) + " 00:00:00";

        //目标年月日
        String date2 = yearSelect + "-" + String.valueOf(monthSelect + 1) + "-" + String.valueOf(daySelect + 1) + " 00:00:00";

        long days = 0;

        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            java.util.Date dateNow = df.parse(date1);
            java.util.Date dateSelected = df.parse(date2);
            long l = dateNow.getTime() - dateSelected.getTime();
            days = l / (24 * 60 * 60 * 1000);
        } catch (Exception e) {
            e.printStackTrace();
        }

        int index = CALENDER_DAY_COUNT - (int)days -1;
        if(index >= 0 && index< CALENDER_DAY_COUNT)
            mCalenderViewPager.setCurrentItem(index);
    }

    private synchronized void getIsszmbalv3PayMasterInfoList(boolean headerOrFooter) {
        if (Isszmbalv3PayMasterActivity.this.isFinishing()) {
            return;
        }
        new getIsszmbalv3PayMasterInfoListTask().execute();
    }

    private class getIsszmbalv3PayMasterInfoListTask extends AsyncTask<Void, Void, List<Isszmbalv3PayFlow>> {
        public getIsszmbalv3PayMasterInfoListTask() {
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected List<Isszmbalv3PayFlow> doInBackground(Void... params) {
            if (Isszmbalv3PayMasterActivity.this.isFinishing()) {
                return null;
            }
            mReadIndex = 0;
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.DAY_OF_MONTH, mPosition - (CALENDER_DAY_COUNT - 1));
            int year = cal.get(Calendar.YEAR);
            int month = cal.get(Calendar.MONTH) + 1;
            int day = cal.get(Calendar.DAY_OF_MONTH);

            Date date = new Date(year - 1900, month - 1, day);
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            mSearchDate = format.format(date);
            SimpleDateFormat format1 = new SimpleDateFormat("yyyy年MM月dd日");
            mSearchDateZh= format1.format(date);
            List<Isszmbalv3PayFlow> result = null;

            if (BarApplication.getInstance().mDatabaseIsSqlServer) {
                result = DatabaseManager.getIsszmbalv3PayFlowInfoListFromSqlServer(Isszmbalv3PayMasterActivity.this, 1, mSearchDate, mSearchBranchNo);
            }else{
                result = DatabaseManager.getIsszmbalv3PayFlowInfoListFromLocal(Isszmbalv3PayMasterActivity.this, 1, mSearchDate,mSearchBranchNo);
            }
            mReadIndex = mReadIndex + result.size();
            return result;
        }

        @Override
        protected void onPostExecute(List<Isszmbalv3PayFlow> result) {
            super.onPostExecute(result);
            if (Isszmbalv3PayMasterActivity.this.isFinishing()) {
                return;
            }

            if (result != null) {
                synchronized (mLock) {
                    mIsszmbalv3PayFlowInfoList = result;
                    Object[] listdata = getListData(mIsszmbalv3PayFlowInfoList);
                    mIsszmbalv3PayFlowGroupInfoList = (List<Isszmbalv3PayFlowGroup>)listdata[0];
                    ArrayList<String> hourValueList = new ArrayList<String>();
                    ArrayList<String> scanValueList = new ArrayList<String>();
                    int groupSize = mIsszmbalv3PayFlowGroupInfoList.size();
                    for(int i=0;i<groupSize;i++){
                        int childSize = mIsszmbalv3PayFlowGroupInfoList.get(i).getChildList().size();
                        hourValueList.add(mIsszmbalv3PayFlowGroupInfoList.get(i).getGroupName());
                        scanValueList.add(String.valueOf(childSize));
                    }

                    float fReceive = 0;     //现金实收款
                    float fBlotout = 0;     //现金抹零
                    float fVIP = 0;          //会员的售出
                    float fNOVIP= 0;         //非会员的售出
                    for(int i=0;i<mIsszmbalv3PayFlowInfoList.size();i++) {
                        Isszmbalv3PayFlow payMaster = mIsszmbalv3PayFlowInfoList.get(i);
                        if (payMaster.payFlowPay_way.equals("CHG")) {
                            fBlotout = fBlotout + payMaster.payFlowPay_amount;
                        } else {
                            fReceive = fReceive + payMaster.payFlowPay_amount;
                        }
                        if( !TextUtils.isEmpty(payMaster.payFlowCard_id)){
                            fVIP = fVIP + payMaster.payFlowPay_amount;
                        }else{
                            fNOVIP = fNOVIP + payMaster.payFlowPay_amount;
                        }
//                        }else if( payMaster.payFlowPay_way.equals("RMB")){
//                            fReceive = fReceive + payMaster.payFlowPay_amount;
//                        }else if( payMaster.payFlowPay_way.equals("WXZ")){
//                            fWX = fWX + payMaster.payFlowPay_amount;
//                        }else if( payMaster.payFlowPay_way.equals("ZFB")){
//                            fZFB = fZFB + payMaster.payFlowPay_amount;
//                        }
                    }
                    DecimalFormat decimalFormat = new DecimalFormat("##,###.0");
                    Calendar cal = Calendar.getInstance();
                    cal.add(Calendar.DAY_OF_MONTH, mPosition -( Isszmbalv3PayMasterActivity.CALENDER_DAY_COUNT -1));
                    int way = cal.get(Calendar.DAY_OF_WEEK);
                    String mWay = null;
                    if( way == 1 ){
                        mWay ="日";
                    }else if( way == 2 ){
                        mWay ="一";
                    }else if ( way == 3 ){
                        mWay ="二";
                    }else if( way == 4 ){
                        mWay ="三";
                    }else if( way == 5 ){
                        mWay ="四";
                    }else if( way == 6 ){
                        mWay ="五";
                    }else if( way == 7 ){
                        mWay ="六";
                    }
//                    int year = cal.get(Calendar.YEAR);
//                    int month = cal.get(Calendar.MONTH) + 1;
//                    int day = cal.get(Calendar.DAY_OF_MONTH);
//                    String lunarDay = mLunarCalendar.getLunarDate(year, month, day, false);
                    mPayMasterDateTv.setText(mSearchDateZh);
                    paymaster_datetime_tv.setText(" 周" + mWay);
                    //paymaster_datetime_tv.setText(" 周" + mWay + lunarDay);
                    mPayMasterTotalTv.setText( decimalFormat.format(fReceive) );
                    //mPayMasterBlotoutTv.setText( decimalFormat.format(fBlotout));    //这个指标有问题
                    paymaster_vip_tv.setText( decimalFormat.format(fVIP));
                    paymaster_novip_tv.setText( decimalFormat.format(fNOVIP));

                    mCalenderAdapter.setAccountsNumber(String.valueOf((int)listdata[1]), hourValueList, scanValueList);

                    mArcProgress.setMax((int)(fReceive));

                    ValueAnimator animator = ValueAnimator.ofFloat(0, fVIP);
                    animator.setDuration(1200);
                    animator.setInterpolator(new DecelerateInterpolator());
                    animator.start();
                    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator valueAnimator) {
                            Float integer = (Float) valueAnimator.getAnimatedValue();
                            mArcProgress.setProgress(integer.intValue());
                        }
                    });
                }
            }
        }
    }

    private class DeleteIsszmbalv3PayMasterInfoTask extends AsyncTask<Void, Void, String> {
        public DeleteIsszmbalv3PayMasterInfoTask() {
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected String doInBackground(Void... params) {
            long row = -1;
            if( BarApplication.getInstance().mDatabaseIsSqlServer){
                row = DatabaseManager.deleteIsszmbalv3PayFlowInfoFromSqlServer(Isszmbalv3PayMasterActivity.this, mSearchDate);
            }
            return String.valueOf(row);
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            getIsszmbalv3PayMasterInfoList(true);
        }
    }

    private Object[] getListData(List<Isszmbalv3PayFlow> payMasterList) {
        Object[] result = new Object[2];
        List<Isszmbalv3PayFlowGroup> groupList = new ArrayList<Isszmbalv3PayFlowGroup>();
        int accountsNum = 0;
        Map<String, String> map = new HashMap<String, String>();
        Map<String, String> map1 = new HashMap<String, String>();

        for (Isszmbalv3PayFlow payMasterInfo : payMasterList) {
            if (!map1.containsKey(payMasterInfo.payFlowFlow_no)) {
                accountsNum++;
                map1.put( payMasterInfo.payFlowFlow_no, payMasterInfo.payFlowFlow_no );
                Time time = payMasterInfo.payFlowOpertime;
                int hour = time.getHours();
                if (!map.containsKey(String.valueOf(hour))) {
                    Isszmbalv3PayFlowGroup groupEntity = new Isszmbalv3PayFlowGroup();
                    groupEntity.setGroupName(String.valueOf(hour));

                    List<Isszmbalv3PayFlow> childList = new ArrayList<Isszmbalv3PayFlow>();
                    childList.add(payMasterInfo);

                    groupEntity.setChildList(childList);
                    groupList.add(groupEntity);
                    map.put(String.valueOf(hour), String.valueOf(hour));
                } else {
                    for (Isszmbalv3PayFlowGroup groupEntity : groupList) {
                        if (groupEntity.getGroupName().equals(String.valueOf(hour))) {
                            List<Isszmbalv3PayFlow> childList = groupEntity.getChildList();
                            childList.add(payMasterInfo);
                        }
                    }
                }
            }
        }
        result[0] = groupList;
        result[1] = accountsNum;
        return result;
    }

    /**
     * @desc
     * @author taoli
     * @time 2017/10/10 0010
     * 0:EXPANDED(展开)   1:COLLAPSED(折叠)   2:INTERNEDIATE(中间)
     */
    private int state = 0;
    private AppBarLayout.OnOffsetChangedListener onOffsetChangedListener = new AppBarLayout.OnOffsetChangedListener() {
        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            mArcProgress.setTranslationX(-ScreenUtil.getScreenSize(getActivity())[0] * Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange()/2 );
            mArcProgress.setTranslationY(-Utils.sp2px(getResources(),325) * Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange()/2);
            mArcProgress.setAlpha(1.0f - (float)Math.abs(verticalOffset) / (float)appBarLayout.getTotalScrollRange());
            mArcProgress.setScaleX(1.0f - (float)Math.abs(verticalOffset) / (float)appBarLayout.getTotalScrollRange());
            mArcProgress.setScaleY(1.0f - (float)Math.abs(verticalOffset) / (float)appBarLayout.getTotalScrollRange());

            paymaster_tips_tv.setTranslationX(ScreenUtil.getScreenSize(getActivity())[0] * Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange() /2);
            paymaster_tips_tv.setTranslationY(-Utils.sp2px(getResources(),325) * Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange()/2);
            paymaster_tips_tv.setAlpha(1.0f - (float)Math.abs(verticalOffset) / (float)appBarLayout.getTotalScrollRange());

            paymaster_total_ll.setTranslationX(-ScreenUtil.getScreenSize(getActivity())[0] * Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange() / 3.0f);
            paymaster_total_ll.setTranslationY(-Utils.sp2px(getResources(),325) * Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange() / 3.0f );
            paymaster_total_ll.setScaleX(1.0f - (float)Math.abs(verticalOffset) / (float)appBarLayout.getTotalScrollRange() * 0.3f);
            paymaster_total_ll.setScaleY(1.0f - (float)Math.abs(verticalOffset) / (float)appBarLayout.getTotalScrollRange() * 0.3f);

            paymaster_wx_payment_ll.setTranslationX(ScreenUtil.getScreenSize(getActivity())[0] * Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange() / 10.5f);
            paymaster_wx_payment_ll.setTranslationY(-Utils.sp2px(getResources(), 300) * Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange() / 2f);
            paymaster_zfb_payment_ll.setTranslationX(ScreenUtil.getScreenSize(getActivity())[0] * Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange() / 2.8f);
            paymaster_zfb_payment_ll.setTranslationY(-Utils.sp2px(getResources(), 360) * Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange() / 2f);

            //paymaster_blotout_ll.setTranslationX(ScreenUtil.getScreenSize(getActivity())[0] * Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange() / 2.8f);
            //paymaster_blotout_ll.setTranslationY(-Utils.sp2px(getResources(),325) * Math.abs(verticalOffset) / appBarLayout.getTotalScrollRange() / 2.2f );

            //i>=0  Toolbar全部显示
            if (verticalOffset == 0) {
                //修改状态标记为展开
                if (state != 0) {
                    state = 0;
                    //StatusBarUtil.setStatusBarColor(MemberEditActivity.this, R.color.transparent, false);
                }
            } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
                //修改状态标记为折叠
                if (state != 1) {
                    state = 1;
                    //StatusBarUtil.StatusBarLightMode(MemberEditActivity.this, R.color.transparent, false);
                }
            } else {
                //修改状态标记为中间
                if (state != 2) {
                    state = 2;
                }
            }
        }
    };
}
